import config from 'config'
import httpFetch from 'share/httpFetch'
const url = `${config.baseUrl}/ledger`;
function urlJoin(params) {
  let res = [];
  for(let key in params){
    res.push(`${key}=${params[key]}`)
  }
  return res.join('&');
}

export default {

  // 凭证定义 -- 获取列表
  getCredentialList(params){
    return httpFetch.get(`${url}/api/journal/template/query/by/page?${urlJoin(params)}`)
  },

  // 凭证定义 -- 新增
  addCredential(params,userOID){
    return httpFetch.post(`${url}/api/journal/template?operatorOid=${userOID}`,params);
  },

  // 凭证定义 -- 更新
  updateCredential(params,userOID){
    return httpFetch.put(`${url}/api/journal/template?operatorOid=${userOID}`,params);
  },

  // 凭证定义 -- 获取核算业务类型列表
  getTypeList(params){
    return httpFetch.get(`${url}/api/functionDef/query/by/setOfBooksId?${urlJoin(params)}`)
  },

  // 凭证定义明细查询
  getCredentialDetail(params){
    return httpFetch.get(`${url}/api/journal/template/query/head/template/detail?${urlJoin(params)}`)
  },

  // 计算器获取树形结构
  getTreeList(params){
    return httpFetch.get(`${url}/api/function/source/group/select/by/function/define/id?${urlJoin(params)}`)
  },

  // 获取行样式的表格属性
  getTableList(setOfBooksId){
    return httpFetch.get(`${url}/api/journal/template/query/line/template/title?setOfBooksId=${setOfBooksId}`);
  },

  // 获取行样式的表格数据
  getRowTable(params){
    return httpFetch.get(`${url}/api/journal/template/query/line/template/detail?${urlJoin(params)}`)
  },

  // 行样式保存
  saveRowStyle(params,userOID){
    return httpFetch.post(`${url}/api/journal/template/scene?operatorOid=${userOID}`,params);
  },

  // 行样式保存
  updateRowStyle(params,userOID){
    return httpFetch.put(`${url}/api/journal/template/scene?operatorOid=${userOID}`,params);
  },

  // 删除行样式
  deleteRowStyle(id){
    return httpFetch.delete(`${url}/api/journal/template/scene?id=${id}`);
  },

  // 计算器存入后台
  saveCalculator(params){
    return httpFetch.post(`${url}/api/journal/linecell/save`,params)
  },

  // 分录生成
  buildEntry(params){
    return httpFetch.post(`${url}/api/journal/create/journal/by/businessCode?${urlJoin(params)}`);
  },

  // 借贷定义树
  getDebitTree(params){
    return httpFetch.get(`${url}/api/dc/define/query/by/setOfBooksId?${urlJoin(params)}`);
  },

  // 查询公式编辑器内容
  getCalculator(params){
    return httpFetch.get(`${url}/api/journal/linecell/query?${urlJoin(params)}`);
  },

  // 删除公司
  deleteCalculator(params){
    return httpFetch.post(`${url}/api/journal/linecell/remove`,params)
  },

  getTransactionList(params) {
    return httpFetch.get(`${url}/api/journal/getTranDetail/by/businessCode/tenantId`, params);
  }

}
